% V20210224 - 18.5 Interfacing GW With a Third Party Android App INCLUDE "GW.bas" % Create a page. p = GW_NEW_PAGE() % Prepare title bar string. title$ = GW_ADD_BAR_TITLE$("GW Barcode Scanner example") % Add title to page. GW_ADD_TITLEBAR(p, title$) % Add a customized button. barcode = GW_ADD_ICON(p, "http://mougino.free.fr/tmp/barcode.png", 32, 32) GW_USE_THEME_CUSTO_ONCE("icon="+GW_ID$(barcode)) GW_ADD_BUTTON(p, "Launch barcode scanner", "ZXING") % Add a title and a textbox. GW_ADD_TITLE(p, "Result:") res = GW_ADD_TEXTBOX(p, "") % Render the page GW_RENDER(p) DO % Wait for user action. r$ = GW_WAIT_ACTION$() % Place here any necessary code to process user actions. % User pressed "Launch barcode scanner" IF r$="ZXING" GOSUB zxing % User tapped on a scanned link ELSEIF IS_IN("LNK:", r$) = 1 BROWSE MID$(r$, 5) END IF % End when BACK key is pressed. UNTIL r$ = "BACK" CLIPBOARD.PUT ClipMem$ % restore clipboard END "End of GW Barcode Scanner demo" zxing: % Sub-routine to call Zxing and wait for result. CLIPBOARD.GET ClipMem$ CLIPBOARD.PUT "||sc#@#" SYSTEM.OPEN SYSTEM.WRITE "am start -a com.google.zxing.client.android.SCAN --user 0" DO CLIPBOARD.GET Zw$ UNTIL Zw$ <> "||sc#@#" & Zw$ <> "" SYSTEM.CLOSE IF Zw$ = "||sc#@#end" GW_MODIFY(res, "text", "Sorry, you get nothing. If you want to start a new scan please make sure that ZXING's clipboard state is switched to on.") ELSE IF IS_IN("http", Zw$) = 1 THEN Zw$ = GW_LINK$(Zw$) GW_MODIFY(res, "text", "Scancode: "+Zw$) ENDIF RETURN